package com.woniuxy.controller;

import com.woniuxy.commons.entity.Medicine;
import com.woniuxy.commons.entity.User;
import com.woniuxy.commons.service.MedicineService;
import com.woniuxy.commons.service.UserService;
import com.woniuxy.commons.utils.ResponseResult;
import com.woniuxy.entity.MedicineOrder;
import com.woniuxy.service.MedicineOrderService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/order")
public class MedicineOrderController {
    @Resource
    private MedicineService MedicineService;
    @Resource
    UserService userService;
    @Resource
    private MedicineOrderService medicineOrderService;
    @ApiOperation(value = "获取所有挂号数据")
    @GetMapping("/MedicineOrder/findAll/{currentPage}/{pageSize}")
    public ResponseResult findAll(@ApiParam(name = "currentPage", value="当前页码",required=true)@PathVariable int currentPage,
                                  @ApiParam(name = "pageSize", value="页面大小",required=true)@PathVariable int pageSize){

        return medicineOrderService.findAll(currentPage,pageSize);
    }
    @PostMapping("/MedicineOrder/search")
    public ResponseResult search(@RequestBody MedicineOrder medicineOrder){

        return  medicineOrderService.search(medicineOrder);
    }
    @GetMapping("/MedicineOrder/findByStatus/{status}")
    public ResponseResult findByStatus(@ApiParam(name = "status", value="支付状态",required=true)@PathVariable int status){
        return medicineOrderService.findByStatus(status);
    }
    @GetMapping("/MedicineOrder/user/findByName/{name}")
    public ResponseResult<User> findByName(@PathVariable String name){
        return userService.findByName(name);
    };
    @GetMapping("/MedicineOrder/findByNo/{no}")
    public ResponseResult findByNo(@PathVariable(value="no") String no) {
        return medicineOrderService .findByNo(no);
    }
    @GetMapping("/MedicineOrder/findIds/{id}")
    public ResponseResult findIds(@PathVariable(value="id") int id) {

        return medicineOrderService . findIds(id);
    }
    @PostMapping("/medicine/medicine/batchFind")
    public ResponseResult<List<Medicine>> findBatch(@RequestBody int[] ids){
        System.out.println(Arrays.toString(ids));
        return MedicineService.findBatch(ids);
    }

}
